# Maintainer: Yuui Tanabe <yuuitanabe@163.com>

_realname=pinentry
pkgbase=mingw-w64-${_realname}
pkgname=(${MINGW_PACKAGE_PREFIX}-${_realname})
pkgver=1.2.1
pkgrel=2
pkgdesc='Collection of simple PIN or passphrase entry dialogs which utilize the Assuan protocol (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.gnupg.org/software/pinentry/index.html"
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libsecret"
         "${MINGW_PACKAGE_PREFIX}-libassuan"
         $([[ ${CARCH} == i686 ]] || echo "${MINGW_PACKAGE_PREFIX}-qt5-base"))
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://www.gnupg.org/ftp/gcrypt/pinentry/pinentry-${pkgver}.tar.bz2"{,.sig}
        "0001-m4-remove-rpath.patch"
        "0002-pinentry-w32-fix-callback.patch")
sha256sums=('457a185e5a85238fb945a955dc6352ab962dc8b48720b62fc9fa48c7540a4067'
            'SKIP'
            '75be629ebcf4fd5dfbb1191d9871c5d5183561049d89c123be72877b350c1ba0'
            'e6de3adec1c39af0959596ff3f1a149b5f5b43f1eea9c460106abecde78409f0')
validpgpkeys=('D8692123C4065DEA5E0F3AB5249B39D24F25E3B6' # Werner Koch (dist sig)
              '6DAA6E64A76D2840571B4902528897B826403ADA' # Werner Koch (dist signing 2020)
              'AC8E115BF73E2D8D47FA9908E98E9B2D19C6C8BD') # Niibe Yutaka (GnuPG Release Key)

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-m4-remove-rpath.patch"
  patch -p1 -i "${srcdir}/0002-pinentry-w32-fix-callback.patch"

  autoreconf -fiv
}

build() {
  local -a _extra_config
  if [[ ${CARCH} != i686 ]]; then
    _extra_config+=("--enable-pinentry-qt")
  fi

  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --disable-pinentry-tty \
    --disable-pinentry-curses \
    --disable-fallback-curses \
    --disable-pinentry-emacs \
    --disable-pinentry-gtk2 \
    --disable-pinentry-gnome3 \
    --enable-libsecret \
    "${_extra_config[@]}"

  # For clang because VERSION file is assumed as header file
  # Required for autotools only, change the file after configure
  mv "${srcdir}/${_realname}-${pkgver}"/{VERSION,version.txt}

  make
}

package()
{
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
